#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, a[500005], m, l[500005], r[500005];

namespace CR200J {
	int dp[1003];
	vector<int> qrs[1003];
	void main() {
		for (int i = 1; i <= m; ++i) {
			qrs[r[i]].push_back(l[i]);
		}
		for (int i = n; i >= 1; --i) {
			int mx = 0;
			for (auto k : qrs[i]) {
				mx = max(mx, k);
			}
			int tmp = dp[i] + a[i];
			for (int j = 0; j <= n; ++j) {
				if (j < mx) dp[j] = tmp;
				else dp[j] = min(dp[j], tmp);
			}
		}
		cout << dp[0] << "\n";
	}
}
/*
	0 0 0 0 0 0
    0 7 0 0 0 0
	0 7 3 0 0 0
	0 
*/
namespace CR400AF {
	struct SGT {
		int tag1[500005*8], tag2[500005*8], res[500005*8];
		#define ls(p) (p << 1)
		#define rs(p) (p << 1 | 1)
		#define NO_TAG -1
		// tag1 : 直接改
		// tag2 : 取最小
		void settag1(int i, int tg) {
			res[i] = tag1[i] = tg;
			if (tag2[i] != NO_TAG) tag2[i] = tg;
		}
		void settag2(int i, int tg) {
			res[i] = min(res[i], tg);
			if (tag2[i] == NO_TAG) tag2[i] = tg;
			else tag2[i] = min(tag2[i], tg);
			tag1[i] = min(tag1[i], tg);
		}
		void push_down(int i) {
			if (tag1[i] != -1) settag1(ls(i), tag1[i]), settag1(rs(i), tag1[i]); tag1[i] = -1;
			if (tag2[i] != -1) settag2(rs(i), tag2[i]), settag2(ls(i), tag2[i]); tag2[i] = -1;
		}
		/*
		   2 3
		 t:2 1

		*/
		int query(int i, int l, int r, int qpos) {
			if (l == r) return res[i];
			int mid = (l + r) / 2;
			push_down(i);
			if (qpos <= mid) return query(ls(i), l, mid, qpos);
			else return query(rs(i), mid + 1, r, qpos);
		}
		void update(int i, int l, int r, int ql, int qr, int k, int typ) {
			if (l > qr || r < ql) return;
			if (l >= ql && r <= qr) {
				if (typ == 1) settag1(i, k);
				else settag2(i, k);
				return;
			}
			int mid = (l + r) / 2; push_down(i);
			update(ls(i), l, mid, ql, qr, k, typ);
			update(rs(i), mid + 1, r, ql, qr, k, typ);
		}
	} t;
	vector<int> qrs[500003];
	void main() {
		memset(t.tag1, 255, sizeof(t.tag1));
		memset(t.tag2, 255, sizeof(t.tag2));
		for (int i = 1; i <= m; ++i) {
			qrs[r[i]].push_back(l[i]);
		}
		for (int i = n; i >= 1; --i) {
			int mx = 0;
			for (auto k : qrs[i]) {
				mx = max(mx, k);
			}
			int tmp = t.query(1, 0, n, i) + a[i];
			if (mx) t.update(1, 0, n, 0, mx - 1, tmp, 1);
			t.update(1, 0, n, mx, n, tmp, 2);
		}
		cout << t.query(1, 0, n, 0) << "\n";
	}
}

signed main() {
	freopen("gonna.in", "r", stdin); freopen("gonna.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i];
	cin >> m; for (int i = 1; i <= m; ++i) cin >> l[i] >> r[i];
	if (n <= 1000 && m <= 1000) {
		CR200J::main();
	} else CR400AF::main();
	return 0;
}
